﻿Public Class FormHorizontalOffset
    Private WithEvents UcDigitalKeyboard1 As ucDigitalKeyboard
    Private update_status As String = INSERT_TYPE
    Private en2 As entity_sppyInfo
    Private objSppyInfo As New clsSppyInfo
    Private objProdInfo As New clsProdInfo
    Private objLhPgd As New clsLhPgd
    Private _sys_id As String
    Dim oper_u As String
    Public Property Sys_id As String
        Get
            Return _sys_id
        End Get
        Set(value As String)
            _sys_id = value
        End Set
    End Property
    Private Sub FormHorizontalOffset_Load(sender As Object, e As EventArgs) Handles MyBase.Load
        oper_u = GetIniFile("LOGIN", "user", "", g_szInitFileName)
        If _sys_id <> "" Then
            update_status = UPDATE_TYPE
            txt_scbh.Enabled = False
            setContent2BySysid()
        Else
            update_status = INSERT_TYPE
            txt_scbh.Focus()
            clearForm2()
        End If
    End Sub

    Private Sub setEntity2()
        en2 = New entity_sppyInfo
        With en2
            .sys_id = _sys_id
            .factory_id = g_factory_id
            .prod_id = txt_scbh.Text.Trim()
            .project_name = txt_Name.Text.Trim()
            .initial_spec = txt_initial_spec.Text.Trim()
            .final_spec = txt_final_spec.Text.Trim()
            .model = txt_model.Text.Trim()
            .check_date = txt_check_date.Text.Trim()
            .horizontal_offset_Measured_value = txt_horizontal_offset_Measured_value.Value
            .horizontal_offset_Maximum = txt_horizontal_offset_Maximum.Value
            .flb_side_length = txt_flb_side_length.Value
            .inspector = cmb_inspector.Text
            .note = tm_note.Text.Trim()
            .ope = oper_u
        End With

    End Sub
    Private Sub setContent2BySysid()
        Dim dt As DataTable = objSppyInfo.selectBySysid(_sys_id)
        If dt.Rows.Count > 0 Then
            Dim row As DataRow = dt.Rows(0)
            txt_scbh.Text = row("prod_id")
            txt_Name.Text = row("project_name")
            txt_initial_spec.Text = row("initial_spec")
            txt_final_spec.Text = row("final_spec")
            txt_model.Text = row("model")
            txt_check_date.Text = row("check_date")
            txt_horizontal_offset_Measured_value.Value = row("horizontal_offset_Measured_value")
            txt_horizontal_offset_Maximum.Value = row("horizontal_offset_Maximum")
            txt_flb_side_length.Value = row("flb_side_length")
            cmb_inspector.Text = row("inspector")
            tm_note.Text = row("note")
        End If
    End Sub

    Private Sub clearForm2()
        For Each obj As Object In Me.Controls
            If obj.GetType.ToString = "DevExpress.XtraEditors.TextEdit" Or
               obj.GetType.ToString = "System.Windows.Forms.ComboBox" Or
               obj.GetType.ToString = "DevExpress.XtraEditors.MemoEdit" Then
                obj.text = String.Empty
            End If
            If obj.GetType.ToString = "DevExpress.XtraEditors.SpinEdit" Then
                obj.text = "0"
            End If
        Next
        txt_initial_spec.Focus()
        txt_check_date.Text = Now()
    End Sub

    Private Sub btnSave1_Click(sender As Object, e As EventArgs) Handles btnSave1.Click
        If chkEmpty(txt_scbh) = False Then Exit Sub
        If chkEmpty(txt_Name) = False Then Exit Sub
        If chkEmpty(txt_initial_spec) = False Then Exit Sub
        If chkEmpty(txt_final_spec) = False Then Exit Sub
        If chkEmpty(txt_model) = False Then Exit Sub
        If chkEmpty(cmb_inspector) = False Then Exit Sub

        If chkZero(txt_horizontal_offset_Measured_value) = False Or chkNegative(txt_horizontal_offset_Measured_value) = False Then
            Exit Sub
        End If
        If chkZero(txt_horizontal_offset_Maximum) = False Or chkNegative(txt_horizontal_offset_Maximum) = False Then
            Exit Sub
        End If
        If chkZero(txt_flb_side_length) = False Or chkNegative(txt_flb_side_length) = False Then
            Exit Sub
        End If
        Dim dtx As DataTable = objProdInfo.getProdInfoById(txt_scbh.Text.Trim(), "10")

        If dtx.Rows.Count = 0 Then
            MsgBox("未检索到硫化后出库的此生产编号信息")
            Exit Sub
        End If

        setEntity2()
        If update_status = INSERT_TYPE Then
            If objSppyInfo.insert(en2) <> -2 Then
                MsgBox("保存成功")
                clearForm2()
            Else
                MsgBox("保存失败")
            End If
        End If
        If update_status = UPDATE_TYPE Then
            If objSppyInfo.update(en2) <> -2 Then
                MsgBox("保存成功")
                Close()
            Else
                MsgBox("保存失败")
            End If
        End If
    End Sub

    Private Sub txt_scbh_KeyPress(sender As Object, e As KeyPressEventArgs) Handles txt_scbh.KeyPress
        If String.IsNullOrEmpty(_sys_id) Then
            If String.IsNullOrEmpty(txt_scbh.Text.Trim()) = False Then
                If e.KeyChar = vbCr Then
                    Dim dttable As DataTable = objProdInfo.selectProdInfo(txt_scbh.Text.Trim())
                    If dttable.Rows.Count > 0 Then
                        txt_initial_spec.Text = dttable.Rows(0)("prod_spec_id")
                        If String.IsNullOrEmpty(dttable.Rows(0)("b_pgd_lh_details_sys_id")) = False Then
                            Dim dtlh As DataTable = objLhPgd.getListBySysId(dttable.Rows(0)("b_pgd_lh_details_sys_id"))
                            txt_Name.Text = dtlh.Rows(0)("mes_project_name")
                        End If
                    End If
                End If
            End If
        End If
    End Sub

    Private Sub txt_MouseDown(sender As Object, e As MouseEventArgs) Handles txt_horizontal_offset_Measured_value.MouseDown, txt_horizontal_offset_Maximum.MouseDown, txt_flb_side_length.MouseDown
        UcDigitalKeyboard1 = New ucDigitalKeyboard
        If sender.MaskBox.Mask.EditMask = "d" Then
            UcDigitalKeyboard1.B_01 = False
        Else
            UcDigitalKeyboard1.B_01 = True
        End If
        UcDigitalKeyboard1.Txt = sender

        Me.Controls.Add(UcDigitalKeyboard1)
        UcDigitalKeyboard1.Show()
        UcDigitalKeyboard1.BringToFront()
        UcDigitalKeyboard1.Focus()

    End Sub

    Private Sub ucdigitalkeyboard1_leave(sender As Object, e As EventArgs) Handles UcDigitalKeyboard1.Leave
        UcDigitalKeyboard1.Dispose()
    End Sub
End Class

Public Class entity_sppyInfo
    Public sys_id As String
    Public factory_id As String
    Public prod_id As String
    Public project_name As String
    Public initial_spec As String
    Public final_spec As String
    Public model As String
    Public check_date As String
    Public horizontal_offset_Measured_value As String
    Public horizontal_offset_Maximum As String
    Public flb_side_length As String
    Public inspector As String
    Public note As String
    Public ope As String
    Public update_time As String
End Class